<template>
	<view class="withdraw-container">
		<!-- 提现类型 -->
		<view class="withdraw-type-section">
			<view class="section-title">提现类型</view>
			<view class="type-display">
				<text class="type-name">微信</text>
			</view>
		</view>
		
		<!-- 提现金额 -->
		<view class="amount-section">
			<view class="section-title">提现金额</view>
			<view class="amount-display">
				<text class="currency-symbol">¥</text>
				<input 
					class="amount-input" 
					type="number" 
					v-model="withdrawAmount"
					placeholder="0"
					@input="onAmountInput"
				/>
			</view>
			<view class="amount-info">
				<text class="min-amount">最低提现金额为0.1元</text>
				<view class="all-amount-section">
					<text class="all-amount-btn" @click="withdrawAll">全部</text>
					<text class="available-amount">可提现金额{{ availableAmount }}元</text>
				</view>
			</view>
		</view>
		
		<!-- 提现按钮 -->
		<view class="withdraw-button-section">
			<u-button 
				@click="submitWithdraw" 
				text="提现" 
				shape="circle" 
				color="#FF6B35"
				:disabled="!canWithdraw"
				:customStyle="buttonStyle"
			></u-button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				withdrawAmount: '',
				availableAmount: '0.00',
				canWithdraw: false
			}
		},
		computed: {
			buttonStyle() {
				return {
					backgroundColor: this.canWithdraw ? '#FF6B35' : '#CCCCCC',
					color: '#FFFFFF'
				}
			}
		},
		methods: {
			// 金额输入处理
			onAmountInput(e) {
				const amount = parseFloat(e.detail.value);
				this.canWithdraw = amount >= 0.1 && amount <= parseFloat(this.availableAmount);
			},
			
			// 全部提现
			withdrawAll() {
				this.withdrawAmount = this.availableAmount;
				this.canWithdraw = parseFloat(this.availableAmount) >= 0.1;
			},
			
			// 提交提现
			submitWithdraw() {
				if (!this.canWithdraw) {
					uni.showToast({
						title: '请输入有效金额',
						icon: 'none'
					});
					return;
				}
				
				uni.showModal({
					title: '确认提现',
					content: `确认提现¥${this.withdrawAmount}到微信吗？`,
					success: (res) => {
						if (res.confirm) {
							this.processWithdraw();
						}
					}
				});
			},
			
			// 处理提现
			processWithdraw() {
				uni.showLoading({
					title: '提现处理中...'
				});
				
				// 模拟提现处理
				setTimeout(() => {
					uni.hideLoading();
					uni.showToast({
						title: '提现申请已提交',
						icon: 'success'
					});
					
					// 返回上一页
					setTimeout(() => {
						uni.navigateBack();
					}, 1500);
				}, 2000);
			}
		}
	}
</script>

<style scoped>
	.withdraw-container {
		background-color: #ffffff;
		min-height: 100vh;
		padding: 40rpx;
	}

	.withdraw-type-section {
		margin-bottom: 40rpx;
	}

	.section-title {
		font-size: 28rpx;
		color: #666666;
		margin-bottom: 20rpx;
	}

	.type-display {
		margin-bottom: 20rpx;
	}

	.type-name {
		font-size: 36rpx;
		font-weight: bold;
		color: #333333;
	}

	.amount-section {
		margin-bottom: 60rpx;
	}

	.amount-display {
		display: flex;
		align-items: center;
		margin-bottom: 20rpx;
	}

	.currency-symbol {
		font-size: 48rpx;
		font-weight: bold;
		color: #333333;
		margin-right: 10rpx;
	}

	.amount-input {
		font-size: 48rpx;
		font-weight: bold;
		color: #333333;
		flex: 1;
	}

	.amount-info {
		display: flex;
		justify-content: space-between;
		align-items: flex-end;
	}

	.min-amount {
		font-size: 24rpx;
		color: #999999;
	}

	.all-amount-section {
		display: flex;
		flex-direction: column;
		align-items: flex-end;
	}

	.all-amount-btn {
		font-size: 28rpx;
		color: #333333;
		margin-bottom: 5rpx;
	}

	.available-amount {
		font-size: 24rpx;
		color: #999999;
	}

	.withdraw-button-section {
		margin-top: 60rpx;
	}

	/* 按钮样式 */
	:deep(.u-button) {
		width: 100%;
		height: 88rpx;
		border-radius: 44rpx;
		font-size: 32rpx;
		font-weight: bold;
		
	}
</style>